<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <!-- 引入样式 -->
  <link rel="stylesheet" href="../../plugins/element-ui/index.css" />
  <link rel="stylesheet" href="../../styles/common.css" />
  <link rel="stylesheet" href="../../styles/page.css" />
</head>
<body>
<div class="addBrand-container" id="member-add-app">
  <div class="container">
    <el-form
            :inline="false"
            label-width="180px"
            class="demo-ruleForm"
    >
      <el-form-item label="供应商编码:" prop="procode">
        <el-input v-model="ruleForm.procode" placeholder="请输入供应商编码" maxlength="20" :disabled="true"/>
      </el-form-item>
      <el-form-item
              label="供应商名称:"
              prop="proname"
      >
        <el-input
                v-model="ruleForm.proname"
                placeholder="请输入供应商名称"
                maxlength="20"
                :disabled="true"
        />
      </el-form-item>

      <el-form-item
              label="供应商详细描述:"
              prop="prodesc"
      >
        <el-input
                v-model="ruleForm.prodesc"
                placeholder="请输入供应商详细描述"
                maxlength="50"
                :disabled="true"
        />
      </el-form-item>

      <el-form-item
              label="供应商联系人:"
              prop="procontact"
      >
        <el-input
                v-model="ruleForm.procontact"
                placeholder="请输入供应商联系人"
                maxlength="20"
                :disabled="true"
        />
      </el-form-item>

      <el-form-item
              label="联系电话:"
              prop="prophone"
      >
        <el-input
                v-model="ruleForm.prophone"
                placeholder="请输入联系电话"
                maxlength="20"
                :disabled="true"
        />
      </el-form-item>

      <el-form-item
              label="地址:"
              prop="proaddress"
      >
        <el-input
                v-model="ruleForm.proaddress"
                placeholder="请输入地址"
                maxlength="50"
                :disabled="true"
        />
      </el-form-item>
      <el-form-item
              label="邮箱:"
              prop="proemail"
      >
        <el-input
                v-model="ruleForm.proemail"
                placeholder="请输入邮箱"
                maxlength="50"
                :disabled="true"
        />
      </el-form-item>

      <el-form-item
              label="创建者:"
              prop="createdby"
      >
        <el-input
                v-model="ruleForm.createdby"
                maxlength="50"
                :disabled="true"
        />
      </el-form-item>

      <el-form-item

              label="创建时间:"
              prop="creationdate"
      >
        <el-input
                v-model="ruleForm.creationdate"
                maxlength="50"
                :disabled="true"
        />
      </el-form-item>


      <el-form-item

              label="更新者:"
              prop="modifyby"
      >
        <el-input
                v-model="ruleForm.modifyby"
                maxlength="50"
                :disabled="true"
        />
      </el-form-item>


      <el-form-item

              label="更新时间:"
              prop="modifydate"
      >
        <el-input
                v-model="ruleForm.modifydate"
                maxlength="50"
                :disabled="true"
        />
      </el-form-item>




      <div class="subBox address">
        <el-form-item>
          <el-button  @click="goBack()">
            退回
          </el-button>
        </el-form-item>
      </div>
    </el-form>
  </div>
</div>
<!-- 开发环境版本，包含了有帮助的命令行警告 -->
<script src="../../plugins/vue/vue.js"></script>
<!-- 引入组件库 -->
<script src="../../plugins/element-ui/index.js"></script>
<!-- 引入axios -->
<script src="../../plugins/axios/axios.min.js"></script>
<script src="../../js/request.js"></script>
<script src="../../api/member.js"></script>
<script src="../../js/validate.js"></script>
<script src="../../js/index.js"></script>
<script>
  new Vue({
    el: '#member-add-app',
    data() {
      return {
        id: '',
        actionType : '',
        ruleForm : {
          procode:'',
          proname: '',
          'prodesc': '',
          'procontact': '',
          'prophone': '',
          'proaddress': '',
          'proemail': '',
          'createdby':'',
          'modifyby':'',
          'creationdate':'',
          'modifydate':'',
        }
      }
    },
    computed: {
    },
    created() {
      this.id = requestUrlParam('id')
      this.actionType = this.id ? 'edit' : 'add'
      if (this.id) {
        this.init()
      }
    },
    mounted() {
    },
    methods: {
      async init () {
        queryEmployeeById(this.id).then(res => {
          if (String(res.code) === '1') {
            console.log(res.data)
            this.ruleForm = res.data
          } else {
            this.$message.error(res.msg || '操作失败')
          }
        })
      },
      submitForm (formName, st) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            if (this.actionType === 'add') {
              const params = {
                ...this.ruleForm,
              }
              addEmployee(params).then(res => {
                if (res.code === 1) {
                  this.$message.success('供应商添加成功！')
                  if (!st) {
                    this.goBack()
                  } else {
                    this.ruleForm = {
                      procode:'',
                      proname: '',
                      'prodesc': '',
                      'procontact': '',
                      'prophone': '',
                      'proaddress': '',
                      'proemail': ''
                    }
                  }
                } else {
                  this.$message.error(res.msg || '操作失败')
                }
              }).catch(err => {
                this.$message.error('请求出错了：' + err)
              })
            } else {
              const params = {
                ...this.ruleForm,
              }
              editUser(params).then(res => {
                if (res.code === 1) {
                  this.$message.success('用户信息修改成功！')
                  this.goBack()
                } else {
                  this.$message.error(res.msg || '操作失败')
                }
              }).catch(err => {
                this.$message.error('请求出错了：' + err)
              })
            }
          } else {
            console.log('error submit!!')
            return false
          }
        })
      },
      goBack(){
        window.parent.menuHandle({
          id: '2',
          url: '/backend/page/member/list.html',
          name: '供应商管理'
        },false)
      }
    }
  })
</script>
</body>
</html>